package com.saatcioglu.android.guessthenumber;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class GfxLevelsList extends ListActivity {

    ArrayList<String> mStrings = new ArrayList<String>();
    ArrayAdapter<String> mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.levelslist_list);
    	SMBGuesstheNumber.isPreferencesChanged = false;        	
        fillData();
    }

    private void fillData() {

        // Now create a simple cursor adapter and set it to display
        for(int i = 0; i < SMBGuesstheNumber.nCurrentLevel; i++){
            mStrings.add(CtrlMaintanence.getInstance().formatLevels(i));
        }
        mAdapter = new ArrayAdapter<String>(this,R.layout.levelslist_row, mStrings);
        setListAdapter(mAdapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if(SMBGuesstheNumber.nCurrentLevel != position){
        	SMBGuesstheNumber.nCurrentLevel = position;
        	SMBGuesstheNumber.isPreferencesChanged = true;        	
        }
        finish();        	
    }
}
